﻿using UnityEngine;

public class PlayerWallIdle : PlayerBaseState {
	Timer _timer = new();
	bool _startSlide;
	public PlayerWallIdle(PlayerController controller, PlayerStateEnum stateName, State<PlayerStateEnum> superFSM, StateFactory<PlayerStateEnum> factory) : base(controller, stateName, superFSM, factory) {
		AddConditionToSelf(() => XInputToWall && _controller.IsTouchingWall && _controller.Velocity.y <= 0);

		//AddNewTransition(PlayerStateEnum.Climb, () => _controller.Up || _controller.DownInput);
	}

	public override void Enter() {
		_controller.PlayAnim(PlayerStateEnum.WallIdle);
		_controller.Velocity = Vector2.zero;
		_timer.Reset();
		_startSlide = false;
	}

	public override void Update() {
		base.Update();
		if (!_startSlide && _timer.Elapsed > _controller.ConfigData.MaxGrabWallTime) {
			_controller.SetGravity(_controller.ConfigData.SlideFromWallAcceleration);
			_controller.PlayAnim(PlayerStateEnum.WallSlide);
			_startSlide = true;
		}
	}

	public override void Exit() {
		_controller.SetGravity(0);
	}
	bool XInputToWall => AreSignsEqual<float, int>(_controller.XInput, _controller.StateData.FaceDir);

}